using System;
using Sony.Vegas;
using System.IO;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Diagnostics;
using System.Windows.Forms;
using System.Xml;
using System.Globalization;


class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        System.Text.StringBuilder builder = new System.Text.StringBuilder();
        //double PlaybackSpeed = 1;
        //string value = "Document 1";
        //if (InputBox("Playback", "Playback speed", ref value) == DialogResult.OK)
        {
        //    PlaybackSpeed = Convert.ToDouble(value);
        }
        Project proj = vegas.Project;
        foreach (Track track in proj.Tracks)
        {
	        foreach(TrackEvent te in track.Events)
	        {
                if (te.MediaType == MediaType.Video)
                {
                   builder.Append("Region add");
             	   Marker marker = null;
               	   marker = new Sony.Vegas.Region(te.Start, te.Length, "label");
                   proj.Regions.Add(marker);
                }
                //builder.Append("Track Event ");
                //builder.Append("playback rate = " + te.PlaybackRate + " start: " + te.Start + " end: " + te.Length + te.MediaType);
		        builder.AppendLine();
		        builder.Append(te.Name).AppendLine();
		        te.Loop = true;
                //te.AdjustPlaybackRate(PlaybackSpeed, true);
		        
                //Marker marker = null;
                //marker = new Sony.Vegas.Region(te.Start, te.Length, "label");
                //proj.Regions.Add(marker);
	        }

        }
	    //MessageBox.Show(builder.ToString());

    }
    public static DialogResult InputBox(string title, string promptText, ref string value)
    {
        Form form = new Form();
        Label label = new Label();
        TextBox textBox = new TextBox();
        Button buttonOk = new Button();
        Button buttonCancel = new Button();

        form.Text = title;
        label.Text = promptText;
        textBox.Text = value;

        buttonOk.Text = "OK";
        buttonCancel.Text = "Cancel";
        buttonOk.DialogResult = DialogResult.OK;
        buttonCancel.DialogResult = DialogResult.Cancel;

        label.SetBounds(9, 20, 372, 13);
        textBox.SetBounds(12, 36, 372, 20);
        buttonOk.SetBounds(228, 72, 75, 23);
        buttonCancel.SetBounds(309, 72, 75, 23);

        label.AutoSize = true;
        textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
        buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
        buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

        form.ClientSize = new Size(396, 107);
        form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
        form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
        form.FormBorderStyle = FormBorderStyle.FixedDialog;
        form.StartPosition = FormStartPosition.CenterScreen;
        form.MinimizeBox = false;
        form.MaximizeBox = false;
        form.AcceptButton = buttonOk;
        form.CancelButton = buttonCancel;

        DialogResult dialogResult = form.ShowDialog();
        value = textBox.Text;
        return dialogResult;
    }

}
